package com.peanut.baby.mvp.bbs.detail;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.peanut.baby.R;
import com.peanut.baby.model.BBSComment;
import com.peanut.baby.mvp.mycontent.MyContentActivity;
import com.peanut.baby.mvp.profile.ProfileActivity;
import com.peanut.baby.util.TimeUtil;
import com.peanut.devlibrary.imageloader.ImageLoader;
import com.peanut.devlibrary.widget.pullrecycle.BaseRecyclerAdapter;
import com.peanut.devlibrary.widget.pullrecycle.BaseViewHolder;

import java.util.List;

/**
 * Created by anonymouslystudio on 2017/8/21.
 */

public class BBSCommentRecyclerAdapter extends BaseRecyclerAdapter<BBSComment>{
    boolean isContentActivity = false;
    public BBSCommentRecyclerAdapter(Context context, List<BBSComment> data) {
        super(context, data);
        if(context instanceof MyContentActivity){
            isContentActivity = true;
        }
    }


    @Override
    protected void convert(BaseViewHolder holder, BBSComment item, int position) {
        super.convert(holder, item, position);
        ImageView avatar = holder.getView(R.id.comment_avatar);
        TextView nick = holder.getView(R.id.comment_nick);
        TextView time = holder.getView(R.id.comment_time);
        TextView index = holder.getView(R.id.comment_index);
        TextView content = holder.getView(R.id.comment_content);

        ImageLoader.getInstance().loadImageView(mContext,item.avatar,avatar);
        if(isContentActivity){
            index.setText("");
        }else{
            index.setText("#" + (position + 1));
        }

        nick.setText(item.nickname);
        time.setText(TimeUtil.getDisplayTimeMillis(item.createTime));
        content.setText(item.content);


        avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ProfileActivity.start(mContext,item.userId+"");
            }
        });
    }

    @Override
    protected void convert(BaseViewHolder holder, final BBSComment item) {


    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_item_bbs_comment;
    }

}
